using Admin2025.Application.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Admin2025.Application.EventHandlers;

/// <summary>
/// 用户删除事件处理器 - 记录审计日志
/// </summary>
public class UserDeletedAuditHandler : INotificationHandler<UserDeletedNotification>
{
    private readonly ILogger<UserDeletedAuditHandler> _logger;

    public UserDeletedAuditHandler(ILogger<UserDeletedAuditHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(UserDeletedNotification notification, CancellationToken cancellationToken)
    {
        var userEvent = notification.UserDeletedEvent;
        
        _logger.LogInformation("用户删除审计: 事件ID={EventId}, 用户ID={UserId}, 用户名={Username}, 删除者={DeletedBy}, 删除时间={OccurredOn}",
            userEvent.EventId,
            userEvent.UserId,
            userEvent.Username,
            userEvent.DeletedBy,
            userEvent.OccurredOn);

        // 这里可以记录到审计日志表
        await Task.CompletedTask;
    }
}
